<?php

class Controller_Help extends Controller_Abstract
{
	
	function actionIndex()
	{
		return $this->display($this->_site['template']);
	}
	function actionAboutus()
	{
		return $this->display($this->_site['template']);
	}
	function actionHowitworks()
	{	
		return $this->display($this->_site['template']);
	}
	function actionHowtoplay()
	{	
		return $this->display($this->_site['template']);
	}
	function actionPrivacy()
	{
		return $this->display($this->_site['template']);
	}
	function actionTerms()
	{
		return $this->display($this->_site['template']);
	}
	function actionContactus()
	{
		return $this->display($this->_site['template']);
	}
	function actionSitemap()
	{
		return $this->display($this->_site['template']);
	}
	function actionUnsub()
	{
		return $this->display($this->_site['template']);
	}
	function actionUnsubing()
	{
		if($this->_context->isPOST()){
			$email = $this->_context->email;
			$password = $this->_context->password;
			$usermodel = new User();
			if($usermodel->valid($email, $password, $this->_view['site']['id'])){
				if(isset($this->_context->unsub))
					$unsub = 1;
				if($usermodel->changeSubscribe($this->_view['user']['id'], $unsub)){
					$infos = array();
					$infos[] = Util::getMessage(3003);
					$_SESSION['infos'] = $infos;
				} else {
					$errors = array();
					$errors = Util::getMessage(3001);
					$_SESSION['errors'] = $errors;
				}				
			}else{
				$errors = array();
				$errors = Util::getMessage(1003);
				$_SESSION['errors'] = $errors;
			}
			return $this->_redirect(url('help/unsubbed'));
			
		}
	}
	function actionUnsubbed()
	{
		if(isset($_SESSION['infos'])){
			$this->_view['infos'] = $_SESSION['infos'];
			unset($_SESSION['infos']);
		}
		if(isset($_SESSION['errors'])){
			$this->_view['errors'] = $_SESSION['errors'];
			unset($_SESSION['errors']);
		}
		
		//logout and clear cookie
		if(($user = $this->_app->currentUser())!==null){
			$userId = $user['id'];
			$this->_app->cleanCurrentUser();
			session_destroy();
			setcookie(Q::ini('acl_cookie_key'), $userId, time()-60, '/', '' . $this->_site['domain'], 0, 1);
		}
		
		return $this->display($this->_site['template']);
	}
	function actionRules(){
		return $this->display($this->_site['template']);
	}
}
?>